package com.situ.mall.controller;

import com.situ.mall.entity.User;
import com.situ.mall.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @RequestMapping("/hello")
    @ResponseBody
    public String hello() {
        return "hello";
    }

    @RequestMapping("/selectAll")
    @ResponseBody
    public List<User> selectAll() {
        System.out.println("UserController.selectAll");
        /*User user1 = new User(1, "zhansgan1", "123", "dfhdf");
        User user2 = new User(2, "zhansgan2", "123", "dfhdf");
        User user3 = new User(3, "zhansgan3", "123", "dfhdf");
        List<User> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);
        list.add(user3);*/
        List<User> list = userService.selectAll();
        return list;
    }

    @RequestMapping("/getUserListPage")
    public String getUserListPage(Model model) {
        System.out.println("UserController.getUserListPage");
        List<User> list = userService.selectAll();
        model.addAttribute("list", list);
        // return "/WEB-INF/jsp/user_list.jsp";
        return "user_list";
    }

    @RequestMapping("/login")
    @ResponseBody
    public String login() {
        System.out.println("UserController.login");
        return "login";
    }

    
}
